package com.ytwl.controller.task;

import com.ytwl.bean.Carriers;
import com.ytwl.bean.RespBean;
import com.ytwl.bean.RespPageBean;
import com.ytwl.service.CarriesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/task")
public class TaskController {

    @Autowired
    CarriesService carriesService;

    @PutMapping("/")
    public RespBean updateCarriersById(@RequestBody Carriers carriers) {
        if (carriesService.updateCarriersById(carriers) == 1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }

    @DeleteMapping("/{id}")
    public RespBean deleteCarriersById(@PathVariable Integer id) {
        if (carriesService.deleteCarriersById(id) == 1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }

    @PostMapping("/")
    public RespBean addTask(@RequestBody Carriers carriers) {
        if (carriesService.addTask(carriers) == 1) {
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败!");
    }

    @GetMapping("/")
    public RespPageBean getAllCarriesByPage(Integer page, Integer size) {
        RespPageBean respPageBean = new RespPageBean();
        respPageBean.setData(carriesService.getAllCarriesByPage(page, size));
        respPageBean.setTotal(carriesService.getTotal());
        return respPageBean;
    }
}
